<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Base\Annotation\Common;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ODM\Document(repositoryClass="App\Repository\SalesJuanRepository")
 */
class SalesJuan
{
    /**
     * @Common(cnName="#",editType="text",listType="text")
     * @ODM\Id(strategy="INCREMENT")
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"juan"})
     */
    private $id;

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ODM\Field( nullable=true)
     * @ORM\Column(type="string", length=255)
     * @Groups({"juan"})
     */
    private $name;

    /**
     * @Common(cnName="抵扣金额",editType="text",listType="text")
     * @ODM\Field( type="raw", nullable=true)
     * @ORM\Column(type="float")
     * @Groups({"juan"})
     */
    private $cut;

    /**
     * @Common(cnName="满足金额",editType="text",listType="text")
     * @ODM\Field( type="raw", nullable=true)
     * @ORM\Column(type="float")
     * @Groups({"juan"})
     */
    private $price;

    /**
     * @Common(cnName="是否启用",editType="switch",listType="text")
     * @ODM\Field( type="boolean", nullable=true)
     * @ORM\Column(type="boolean", nullable=true)
     * @Groups({"juan"})
     */
    private $isUse;

    /**
     * @Common(cnName="期限",editType="text",listType="text")
     * @ODM\Field(type="string")
     * @ORM\Column(type="string", length=255)
     * @Groups({"juan"})
     */
    private $expireDay;

    /**
     * @Common(cnName="类型",editType="select",listType="text")
     * @ODM\EmbedOne(targetDocument="App\Entity\ComCategory")
     * @ORM\ManyToOne(targetEntity="App\Entity\ComCategory")
     * @Groups({"com"})
     */
    private $cat;

//    /**
//     * @Common(cnName="类型",editType="select",listType="text")
//     * @ODM\ReferenceOne(targetDocument="App\Entity\ComCategory")
//     * @ORM\ManyToOne(targetEntity="App\Entity\ComCategory")
//     * @Groups({"com"})
//     */
//    private $cat;

    /**
     * @ODM\ReferenceMany(targetDocument="App\Entity\SalesUserJuan", mappedBy="juan", orphanRemoval=true)
     * @ORM\OneToMany(targetEntity="App\Entity\SalesUserJuan", mappedBy="juan", orphanRemoval=true)
     */
    private $users;

    public function __construct()
    {
        $this->users = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getCut(): ?float
    {
        return $this->cut;
    }

    public function setCut(float $cut): self
    {
        $this->cut = $cut;

        return $this;
    }

    public function getPrice(): ?float
    {
        return $this->price;
    }

    public function setPrice(float $price): self
    {
        $this->price = $price;

        return $this;
    }

    public function getIsUse(): ?bool
    {
        return $this->isUse;
    }

    public function setIsUse(?bool $isUse): self
    {
        $this->isUse = $isUse;

        return $this;
    }

    public function getExpireDay(): ?string
    {
        return $this->expireDay;
    }

    public function setExpireDay(string $expireDay): self
    {
        $this->expireDay = $expireDay;

        return $this;
    }

    public function getCat(): ?ComCategory
    {
        return $this->cat;
    }

    public function setCat(ComCategory $cat): self
    {
        $this->cat = $cat;

        return $this;
    }

    /**
     * @return Collection|SalesUserJuan[]
     */
    public function getUsers(): Collection
    {
        return $this->users;
    }

    public function addUser(SalesUserJuan $user): self
    {
        if (!$this->users->contains($user)) {
            $this->users[] = $user;
            $user->setJuan($this);
        }

        return $this;
    }

    public function removeUser(SalesUserJuan $user): self
    {
        if ($this->users->contains($user)) {
            $this->users->removeElement($user);
            // set the owning side to null (unless already changed)
            if ($user->getJuan() === $this) {
                $user->setJuan(null);
            }
        }

        return $this;
    }
}
